/**********************************************************************************
* CLASS
*		Content
*
* DESCRIPTION
* 		Image manipulate function set:
*			- setText
*		Common function set:
*			- genDomObj (Use by Genesis for create image by using dom.)
*			- loadDefault (For loading default value.)
*
* REVISION HISTORY
*		Revision 1.0 2008/09/06 Atthaboon S.
*		First Release
*
**********************************************************************************/
var Content = Class.create({

	/****************************************************
	* FUNCTION
	*		initialize
	*
	* DESCRIPTION
	* 		initialize the Genesis object.
	*
	* ARGUMENTS
	*		position_x		   	:	Table position of x at north left Genesis corner.
	*		position_y 	   	   	:	Table position of y at north left Genesis corner.
	*		content			: 	Content (HTML Dom)
	*
	****************************************************/
  	initialize: function(position_x,position_y,content)
  	{
		this.domObj = new Element('div', { 'style':'text-align:left;position:absolute; left:'+position_x+'px;top:'+position_y+'px;overflow:hidden; width: 300px; height:300px;'});
		this.domObj.innerHTML = content;
		//this.domObj.style.backgroundColor = "white";
		
		this.property = null;
	},
	
	/****************************************************
	* FUNCTION 
	*		getDomType
	*
	* DESCRIPTION
	* 		Use by Genesis for get Genesis dom Component Type.
	*
	* ARGUMENTS
	*
	****************************************************/
	getDomType : function()
	{
		return "Content";
	},	
	
	/****************************************************
	* FUNCTION 
	*		getDomObj
	*
	* DESCRIPTION
	* 		Use by Genesis for get image dom Component.
	*
	* ARGUMENTS
	*
	****************************************************/
	getDomObj : function()
	{
		return this.domObj;
	},
	
	/****************************************************
	* FUNCTION 
	*		generatePropertyBar
	*
	* DESCRIPTION
	* 		Generate Dom Property Bar
	*
	* ARGUMENTS
	*
	****************************************************/
	generatePropertyBar : function()
	{
		var  ContentDomObj = $(this.domObj);
	
		this.property = new PropertyBar("Content",600);
		this.width_box       	  = this.property.addTextBox('Width','px','5',0);
		this.width_box.value      = parseInt($(this.domObj).style.width);
		this.width_box.onchange   = function() {
			ContentDomObj.style.width = this.value+'px';
			setResizeAreaPosition(_dragElement);
		}
		
		this.height_box      	  = this.property.addTextBox('Height','px','5',0);
		this.height_box.value     = parseInt($(this.domObj).style.height);
		this.height_box.onchange   = function() {
			ContentDomObj.style.height = this.value+'px';
			setResizeAreaPosition(_dragElement);
		}
		
		this.position_x_box  	  = this.property.addTextBox('Positon X','px','5',1);
		this.position_x_box.value = parseInt($(this.domObj).style.left);
		this.position_x_box.onchange   = function() {
			ContentDomObj.style.left = this.value+'px';
			setResizeAreaPosition(_dragElement);
		}
		
		this.position_y_box  	  = this.property.addTextBox('Positon Y','px','5',1);
		this.position_y_box.value = parseInt($(this.domObj).style.top);
		this.position_y_box.onchange   = function() {
			ContentDomObj.style.top = this.value+'px';
			setResizeAreaPosition(_dragElement);
		}

		// Button for edit text
		this.edit_button_box	  = this.property.addButton('Edit Text',1);
		this.edit_button_box.onmousedown = function() {
			
			gen_property.getDomObj().style.display = 'none';
			
			document.getElementById('whizzywigEditor').style.display = 'block';
			// display Edit text whizzywig
			divTextEditor = _dragElement.getDomObj();
			//alert(_dragElement.toXML());
			setTextHTML(ContentDomObj.innerHTML);
		}
	},
	
	/****************************************************
	* FUNCTION 
	*		getProperty
	*
	* DESCRIPTION
	* 		Get Image Property
	*
	* ARGUMENTS
	*
	****************************************************/	
	getProperty : function()
	{	
		// Is not generate property yet do generate it's
		
		if(this.property == null)
		{
			this.generatePropertyBar();
		}
		else if(this.property.getDomObj().innerHTML == '')
		{
			this.generatePropertyBar();
		}
		return this.property.getDomObj();
	},	
	
    /****************************************************
	* FUNCTION 
	*		syncProperty
	*
	* DESCRIPTION
	* 		Sync Image Property
	*
	* ARGUMENTS
	*
	****************************************************/	
	syncProperty : function()
	{
		this.width_box.value      = parseInt($(this.domObj).style.width);
		this.height_box.value     = parseInt($(this.domObj).style.height);
		this.position_x_box.value = parseInt($(this.domObj).style.left);
		this.position_y_box.value = parseInt($(this.domObj).style.top);
	},

	
	/****************************************************
	* FUNCTION 
	*		setSize
	*
	* DESCRIPTION
	* 		Set Content size.
	*
	* ARGUMENTS
	*		width		   		:	width in px.
	*		height 	   	   	:	height in px.
	*
	****************************************************/
	setSize : function(width,height)
	{	
		$(this.domObj).setStyle({
		  	width: width+'px',
		  	height: height+'px'
		});
	},
	
	/****************************************************
	* FUNCTION 
	*		setPosition
	*
	* DESCRIPTION
	* 		Set Flash position.
	*
	* ARGUMENTS
	*		position_x		   	:	position x in px.
	*		position_y 	   	   	:	position y in px.
	*
	****************************************************/
	setPosition : function(position_x,position_y)
	{	
		$(this.domObj).setStyle({
		  	left: position_x+'px',
		  	top: position_y+'px'
		});
	},
	
	/****************************************************
	* FUNCTION 
	*		setText
	*
	* DESCRIPTION
	* 		Set Text Content.
	*
	* ARGUMENTS
	*		width		   	:	width in px.
	*		height 	   	   	:	height in px.
	*
	****************************************************/
	setText : function(content)
	{	
		this.domObj.innerHTML = content;
	}

});